package com.hmall.common.config;

import org.springframework.amqp.rabbit.connection.RabbitAccessor;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
//条件注解，当存在指定类时，加载该类
@ConditionalOnClass(RabbitAccessor.class)//当存在RabbitAccessor类时，加载该类
public class MqConfig {
    @Bean
    public MessageConverter messageConverter(){
        Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
        //设置每一个信息都携带一个id
        converter.setCreateMessageIds(true);
        return converter;
    }
}



